package com.lbj.googleplay.googleplay100.ui.fragment;

import android.view.View;

import com.lbj.googleplay.googleplay100.domain.AppInfo;
import com.lbj.googleplay.googleplay100.domain.SubjectInfo;
import com.lbj.googleplay.googleplay100.http.protocol.SubjectProtocol;
import com.lbj.googleplay.googleplay100.ui.adapter.MyBaseAdapter;
import com.lbj.googleplay.googleplay100.ui.holder.BaseHolder;
import com.lbj.googleplay.googleplay100.ui.holder.SubjectHolder;
import com.lbj.googleplay.googleplay100.ui.view.LoadingPage;
import com.lbj.googleplay.googleplay100.ui.view.MyListView;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import java.util.ArrayList;

/*
* 专题
* */
public class SubjectFragment extends BaseFragment {

    private ArrayList<SubjectInfo> data;

    @Override
    public View onCreateSuccessView() {
        MyListView listView = new MyListView(UIUtils.getContext());
        listView.setAdapter(new SubjectAdapter(data));
        return listView;
    }

    @Override
    public LoadingPage.ResultState onLoad() {
        SubjectProtocol protocol = new SubjectProtocol();
        data = protocol.getData(0);
        return check(data);
    }

    class SubjectAdapter extends MyBaseAdapter<SubjectInfo>{


        public SubjectAdapter(ArrayList<SubjectInfo> list) {
            super(list);
        }

        @Override
        public BaseHolder<SubjectInfo> getHolder(int position) {
            SubjectHolder holder = new SubjectHolder();
            return holder;
        }

        @Override
        public ArrayList<SubjectInfo> onLoadMore() {
            SubjectProtocol protocol = new SubjectProtocol();
            ArrayList<SubjectInfo> moreData = protocol.getData(getListSize());
            return moreData;
        }
    }
}
